$(function(){
    $(".search input").focus(function(){
        $(this).parent('div').css('border','2px solid #FF7D23');
    }).blur(function(){
        $(this).parent('div').css('border','2px solid #EBAE85');
    });
    $('.to-message a').click(function(e){
        e.preventDefault();
        $('#mask-box1').removeClass('hide');
    });
    $('#mask-box1 .confirm .cancel').click(function(e){
        e.preventDefault();
        $('#mask-box1').addClass('hide');
        $('#mask-box1 textarea').val("");
    });
    $('#mask-box1 .confirm .add').click(function(e){
        e.preventDefault();
        var path = getRootPath();
        var distributorId= $('#search').attr('data-id');
        var message = $('.message-block').find('textarea').val();
        $.ajax({
			type:"GET",
			url:path+"/message/messageAdd",
			data:{},
			success:function(data){
				if(data.isSuccess==0){
					alertBox(0,data.msg);
				}else{
					alertBox(1,data.data);
					$('#mask-box1').addClass('hide');
			        $('#mask-box1 textarea').val("");
				}
			}
		})
        
    })
    $('.msg-box>ul li').click(function(){
    	 var path = getRootPath();
        $(this).addClass('active').siblings('li').removeClass('active');
        if($(this).hasClass('tab1')){
            $('.service-message').removeClass('hide').siblings('div').addClass('hide');
        }else if($(this).hasClass('tab2')){
            $('.msg-box').css('height','245');
            $('.notice').css('height','245');
            $('.notice').addClass('active').removeClass('hide').siblings('div').addClass('hide');
        }else if($(this).hasClass('tab3')){
            $('.leave-message').removeClass('hide').siblings('div').addClass('hide');
        }
        
        //消息
        if($(this).text()=='公告'){
        	$.ajax({
				type:"GET",
				url:path+"/message/noticeList",
				data:{},
				success:function(data){
					
				}
			});
        }else if($(this).text()=='留言回复'){
        	$.ajax({
				type:"GET",
				url:path+"/message/messageReplyList",
				data:{},
				success:function(data){
					var html = "";
					for(var i = 0;i <data.length;i++){
						if(data[i].isRead ==0){
							html +=
							" <div class='msg-item clearfix' data-id='"+data[i].distributorId+"' data-messageId='"+data[i].id+"'>"
                            +"<b class='fl'></b>"
                            +"<p class='fl'>"+data[i].distributorName+"</p>"
                            +"<p class='fl'><span class='time'>"+data[i].createShowTime+"</span><span class='reply'>回复："+data[i].message+"</span></p>"
                            +"</div>"
						}else{
							html +=
								" <div class='msg-item clearfix visited' data-id='"+data[i].distributorId+"'>"
	                            +"<b class='fl'></b>"
	                            +"<p class='fl'>"+data[i].distributorName+"</p>"
	                            +"<p class='fl'><span class='time'>"+data[i].createShowTime+"</span><span class='reply'>回复："+data[i].message+"</span></p>"
	                            +"</div>"
						}
					}
					html+="<i>查看更多></i>";
					$('.leave-message').html(html);
				}
			});
        }else if($(this).text()=='业务消息'){
        	$.ajax({
				type:"GET",
				url:path+"/message/reminderList",
				data:{},
				success:function(data){
					var html = "";
					
					for(var i = 0;i <data.length;i++){
						if(data[i].isRead ==0){
							html +=
							" <div class='msg-item clearfix'>"
                            +"<b class='fl'></b>"
                            +"<p class='fl'>"+data[i].message+"<span>"+data[i].createShowTime+"</span></p>"
                            +"</div>"
						}else{
							html +=
								" <div class='msg-item clearfix visited'>"
	                            +"<b class='fl'></b>"
	                            +"<p class='fl'>"+data[i].message+"<span>"+data[i].createShowTime+"</span></p>"
	                            +"</div>"
						}
					}
					$('.service-message').html(html);
				}
			});
        	
        }
        
    });
    //点击更多
    $('.msg-box').on('click','.leave-message i',function(){
    	var path = getRootPath();
    	window.location.href=path+"/message/messageReplyAll"; 
    })
      $('.msg-box').on('click','.notice i',function(){
    	console.log("bbb");
    })
});
$(document).ready(function(){
	var path = getRootPath();
	$.ajax({
		type:"GET",
		url:path+"/message/reminderList",
		data:{},
		success:function(data){
			var html = "";
			
			for(var i = 0;i <data.length;i++){
				if(data[i].isRead ==0){
					html +=
					" <div class='msg-item clearfix'>"
                    +"<b class='fl'></b>"
                    +"<p class='fl'>"+data[i].message+"<span>"+data[i].createShowTime+"</span></p>"
                    +"</div>"
				}else{
					html +=
						" <div class='msg-item clearfix visited'>"
                        +"<b class='fl'></b>"
                        +"<p class='fl'>"+data[i].message+"<span>"+data[i].createShowTime+"</span></p>"
                        +"</div>"
				}
			}
			$('.service-message').html(html);
		}
	});
	
	//留言链接
	$('.leave-message').on('click','.msg-item',function(){
		var path = getRootPath();
		 var distributorId = $(this).attr('data-id');   
		 var messageId = $(this).attr('data-messageId'); 
		 window.location.href=path+"/message/messageDetail?distributorId="+distributorId+"&messageId="+messageId; 
	})
	//我的订单
	$('.top-bar .my-order .order-list').on('click','p:nth-child(1)',function(){
		var path = getRootPath();
		 window.location.href=path+"/order/orderList";
	})
	//我的退单
	$('.top-bar .my-order .order-list').on('click','p:nth-child(2)',function(){
		var path = getRootPath();
		window.location.href=path+"/material/materialList";
	})
	//我的账号
	$('.profine .my').on('click','p:nth-child(1)',function(){
		var path = getRootPath();
		window.location.href=path+"/customer/customerAndUser";
	})
	//公司信息
	$('.profine .my').on('click','p:nth-child(2)',function(){
		var path = getRootPath();
		window.location.href=path+"/customer/customerdetail";
	})
	//系统设置
	$('.profine .my').on('click','p:nth-child(3)',function(){
		var path = getRootPath();
		window.location.href=path+"/customer/customerUserList";
	})
	//首页
	$('.home').on('click',function(){
		var path = getRootPath();
		window.location.href=path+"/product/getIndex";
	})
	//退出
	$('.profine .my').on('click','p:nth-child(4)',function(){
		var path = getRootPath();
		window.location.href = path+"/register/quitLogin";
	})
	//我收藏的
	$('.service-block').on('click','li',function(){
		var path = getRootPath();
		console.log($('.service-block ul li').index(this));
		if($('.service-block ul li').index(this)+1==1){
			window.location.href = path+"/collect/getAllCollect?selectLabel=1";
		}else if($('.service-block ul li').index(this)+1==2){
			window.location.href = path+"/collect/getAllOrderContainProduct?selectLabel=2";
		}else if($('.service-block ul li').index(this)+1==3){
			window.location.href =path+ "/collect/getAllBrowser?selectLabel=3";
		}
	})
});
/*获取页面地址的参数*/
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
    var r = window.location.search.substr(1).match(reg);
    if (r!=null) return (r[2]); return null;
}
//将数字转换为人民币格式
function cc(s){
    if(/[^0-9\.]/.test(s)) return "invalid value";
    s=s.replace(/^(\d*)$/,"$1.");
    s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
    s=s.replace(".",",");
    var re=/(\d)(\d{3},)/;
    while(re.test(s))
        s=s.replace(re,"$1,$2");
    s=s.replace(/,(\d\d)$/,".$1");
    return "￥" + s.replace(/^\./,"0.")
}